package com.zito.health.controller;

/**
 * Created by Administrator on 2019/11/17.
 */

import com.alibaba.fastjson.JSONArray;
import com.zito.health.common.enums.ResultCode;
import com.zito.health.common.result.PlatformResult;
import com.zito.health.entity.Item;
import com.zito.health.entity.ItemExpertConclusion;
import com.zito.health.entity.ItemExpertDeclare;
import com.zito.health.service.ItemExpertConclusionService;
import com.zito.health.service.ItemExpertDeclareService;
import com.zito.health.service.ItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 项目结题专家审核表
 */
@Slf4j
@RestController
@RequestMapping("/item/expertConclusion")
public class ItemExpertConclusionController {

    @Autowired
    private ItemExpertConclusionService itemExpertConclusionService;
    @Autowired
    private ItemService itemService;

    /**
     * @param itemIds
     * @param ids
     * @return
     */
    @PostMapping("/save")
    public PlatformResult save(@RequestParam(value = "itemIds[]") Integer[] itemIds,@RequestParam(value = "ids[]") Integer[] ids) {
        if (itemIds != null && itemIds.length > 0) {
            for(Integer itemId : itemIds){
                Item item = itemService.queryById(itemId);
                if(item.getStates() == 1){
                    item.setId(itemId);
                    item.setStates(1);
                    itemService.update(item);
//                    itemExpertConclusionService.save(itemId,ids);
                }
            }
            return PlatformResult.success();
        } else {
            return PlatformResult.failure(ResultCode.DATA_IS_WRONG);
        }
    }

    /**
     * 修改专家评审意见
     * @param item
     * @return
     */
    @PostMapping("/update")
    public PlatformResult update(ItemExpertConclusion item) {
        itemExpertConclusionService.update(item);
        return PlatformResult.success();
    }

    /**
     * 新增/修改专家评审意见
     *
     * @param item
     * @return
     */
    @PostMapping("/saveConclusion")
    public PlatformResult saveConclusion(ItemExpertConclusion item) {
        item.setStates(1);
        itemExpertConclusionService.saveConclusion(item);
        return PlatformResult.success();
    }

    /**
     * 查询\
     * @param item
     * @return
     */
    @PostMapping("/query")
    public PlatformResult query(ItemExpertConclusion item) {
        return PlatformResult.success(itemExpertConclusionService.queryOne(item));
    }

    /**
     * 专家评审结果列表
     *
     * @param item
     * @return
     */
    @PostMapping("/list")
    public PlatformResult list(ItemExpertConclusion item) {
        return PlatformResult.success(itemExpertConclusionService.query(item));
    }

}
